import { defineStore } from "pinia";
import { ref } from "vue";
import { mySchoolStore } from "../../store";

const riderUserCenter=uniCloud.importObject(`rider-user-center`,{customUI: true})

export const myAccountOverviewStore=defineStore(`accountOverview`,()=>{
    const accountOverview=ref({
        toDayIncome:0,        //今日预计收入
        toCompleteOrder:0,      //今天完成订单
        wallet:{    
            available_amount:0,     //可用金额
            freeze_amount:0     //冻结金额
        },  //用户钱包信息
    });

    async function getMyAccountOverview(){
        const schoolStore=mySchoolStore()
        const schoolId=schoolStore.mySchool._id;

        const {data,myErrCode} =  await riderUserCenter.myUserAccountOverview(schoolId);
        if(myErrCode === 0){
            console.log(data)
            accountOverview.value=data
        }
    }
    
    return {
        accountOverview,
        getMyAccountOverview,
    }
})

export const myRiderUserStore=defineStore(`riderUser`,()=>{
    const myUserInfo=ref({
        _id:``, //用户ID
    });
    
    const userInfo= uniCloud.getCurrentUserInfo()
    myUserInfo.value._id=userInfo.uid

    return {
        myUserInfo,
    }
})